package com.buli.blmall.admin.common.controller;

import com.buli.blmall.admin.common.request.PwdLogin;
import com.buli.blmall.admin.common.request.SmsLogin;
import com.buli.blmall.admin.common.response.Result;
import com.buli.blmall.admin.common.domain.SysLoginUser;
import com.buli.blmall.admin.common.service.SysLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiang.gao
 * @date 2024/12/18 14:41
 */
@RestController
@RequestMapping("/system")
public class SysLoginController {

    @Autowired
    private SysLoginService sysLoginService;

    /**
     * 密码登录
     * @param pwdLogin
     * @return
     */
    @PostMapping("/login")
    public Result<SysLoginUser> login(@Validated @RequestBody PwdLogin pwdLogin) {
        SysLoginUser login = sysLoginService.pwdLogin(pwdLogin);
        return Result.success(login);
    }

    /**
     * 短信验证码登录
     * @param smsLogin
     * @return
     */
    @PostMapping("/smsLogin")
    public Result<SysLoginUser> smsLogin(@Validated @RequestBody SmsLogin smsLogin) {
        SysLoginUser login = sysLoginService.smsLogin(smsLogin);
        return Result.success(login);
    }

    /**
     *
     */
    @PostMapping("/logout")
    public Result<?> logout() {
        sysLoginService.logout();
        return Result.success();
    }

}
